<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

//echo 'test';
require_once DISCUZ_ROOT.'./source/plugin/donkey_activity/donkey_activity.func.php';
echo '<link rel="stylesheet" type="text/css" href="./source/plugin/donkey_activity/static/style.css" />';
echo <<<TXT
<style type="text/css">
textarea.wd{width:250px}
select.wd{width:200px}
</style>
TXT;

if(!submitcheck('exist_submit') && !submitcheck('new_submit')) {
	showformheader('plugins&operation=config&do='.$pluginid.'&identifier=donkey_activity&pmod=admin_properties', 'class="cpform" onsubmit="return setcity()"');
	showtableheader('existed_activity_properties');
	$query = DB::query("SELECT * FROM ".DB::table('donkey_activity_property')." WHERE propid like 'prop_%' ORDER BY showorder");
	showsubtitle(array('name', 'type', 'description', 'enable', 'show_columns', 'show_order', 'default_value'));
	$temp=0;
	while($group = DB::fetch($query)) {
	//echo strpos($group['propid'],'prop_');exit(1);
	if(strpos($group['propid'],'prop_')===0){
		$temp=max(intval(str_replace('prop_', '', $group['propid'])), $temp);
	}
	//var_dump($default_value);
	showtablerow('', array('class="td23"', 'class="td23"', 'class="td23"', 'class="td23"', 'class="td23"', 'class="td25"', ''), array(
		'<input type="text" class="txt" size="200" name="'.$group['propid'].'_name" value="'.$group['propname'].'">', 
		cplang('plugins_edit_vars_type_'.$group['type']),
		'<input type="text" class="width200" size="200" name="'.$group['propid'].'_descrip" value="'.$group['descrip'].'">',
		get_default_enable($group['enable'], $group['propid']),
		get_default_radio(($group['showwidth']==1)?1:2, $group['propid'].'_showwidth', array(2=>'2', 1=>'1')),
		'<input type="text" class="txt" size="3" name="'.$group['propid'].'_showorder" value="'.$group['showorder'].'">',
		get_default_field($group['type'], $group['value'], $group['defval'], $group['propid'])
	));
	}

//pauli, 显示提交按钮，来自这里 \source\function\function_admincp.php
//function showsubmit($name = '', $value = 'submit', $before = '', $after = '', $floatright = '', $entersubmit = true)
	showhiddenfields(array('prop_num' => $temp));
	showsubmit('exist_submit','submit');
	showtablefooter();
	showformfooter();

//第二个表单
	showformheader('plugins&operation=config&do='.$pluginid.'&identifier=donkey_activity&pmod=admin_properties', 'class="pb200 cpform"', 'newform');
	$temp++;
	showhiddenfields(array('propid' => 'prop_'.$temp));
	showtableheader('add_new_activity_properties');
	showsubtitle(array('name', 'type', 'description', 'enable', 'show_columns', 'show_order', 'default_value'));
	showtablerow('', array('class="td23"', 'class="td23"', 'class="td23"', 'class="td23"', 'class="td23"', 'class="td25"', ''), array(
		'<input type="text" class="txt" size="30" name="new_name">',
		'<select class="width100" name="new_type" onchange="changeType(this.value);">
			<option value="number">'.cplang('plugins_edit_vars_type_number').'</option>
			<option value="text" selected>'.cplang('plugins_edit_vars_type_text').'</option>
			<option value="textarea">'.cplang('plugins_edit_vars_type_textarea').'</option>
			<option value="radio">'.cplang('plugins_edit_vars_type_radio').'</option>
			<option value="select">'.cplang('plugins_edit_vars_type_select').'</option>
			<option value="date">'.cplang('plugins_edit_vars_type_date').'</option>
			<option value="datetime">'.cplang('plugins_edit_vars_type_datetime').'</option>
			<option value="richtext">高级编辑框(richtext)</option>
		</seletc>',
		'<input type="text" class="width200" size="500" name="new_descrip">',
		get_default_enable(0, 'new'),
		get_default_radio(2, 'new_showwidth', array(2=>'2', 1=>'1')),
		'<input type="text" class="txt" size="200" name="new_showorder" value="'.$temp.'">',
		'<div id="new_value_div"><input type="text" id="new_value" class="width200" size="15" name="new_value"></div><div id="new_defval_div" style="display:none">waiting...</div>'
	));
	showsubmit('new_submit', 'submit');
	showtablefooter();
	showformfooter();
} else if(submitcheck('exist_submit')){
	$prop_num=intval($_G['gp_prop_num']);
	for($i=0;$i<$prop_num;$i++){
		$pre = 'gp_prop_'.$i.'_';
		if($_G[$pre.'name']){
			$_G[$pre.'value'] = $_G[$pre.'value'] ? trim($_G[$pre.'value']) : '';
			$_G[$pre.'defval'] = $_G[$pre.'defval'] ? trim($_G[$pre.'defval']) : '';
			$_G[$pre.'descrip'] = $_G[$pre.'descrip'] ? trim($_G[$pre.'descrip']) : '';
			if($_G['gp_prop_'.$i]){
				$_G[$pre.'value'] = $_G['gp_prop_'.$i];
				$_G[$pre.'defval'] = '';
			}
			$data = array(
				//'propid' => $_G['gp_propid'],
				'propname' => $_G[$pre.'name'],
				'descrip' => $_G[$pre.'descrip'],
				//'type' => $_G[$pre.'type'],
				'enable' => $_G[$pre.'enable'],
				'defval' => $_G[$pre.'defval'],
				'value' => $_G[$pre.'value'],
				'showwidth' => $_G[$pre.'showwidth'],
				'showorder' => $_G[$pre.'showorder'],
			);
			DB::update('donkey_activity_property', $data, 'propid=\'prop_'.$i.'\'');
		}
	}
	cpmsg('success', "action=plugins&operation=config&do={$pluginid}&identifier=donkey_activity&pmod=admin_properties", 'succeed' ,array('return' => $return));
} else if(submitcheck('new_submit')){
	if($_G['gp_propid'] && $_G['gp_new_name'] && $_G['gp_new_type']){
		$_G['gp_new_type'] = $_G['gp_new_type'] ? trim($_G['gp_new_type']) : 'text';
		$_G['gp_new_value'] = $_G['gp_new_value'] ? trim($_G['gp_new_value']) : '';
		$_G['gp_new_defval'] = $_G['gp_new_defval'] ? trim($_G['gp_new_defval']) : '';
		$_G['gp_new_descrip'] = $_G['gp_new_descrip'] ? trim($_G['gp_new_descrip']) : '';
		$data = array(
			'propid' => $_G['gp_propid'],
			'propname' => $_G['gp_new_name'],
			'descrip' => $_G['gp_new_descrip'],
			'type' => $_G['gp_new_type'],
			'enable' => $_G['gp_new_enable'],
			'defval' => $_G['gp_new_defval'],
			'value' => $_G['gp_new_value'],
			'showwidth' => $_G['gp_new_showwidth'],
			'showorder' => $_G['gp_new_showorder'],
		);
		DB::insert('donkey_activity_property', $data, 1);
	}
	cpmsg('success', "action=plugins&operation=config&do={$pluginid}&identifier=donkey_activity&pmod=admin_properties", 'succeed' ,array('return' => $return));
}
echo '<script type="text/javascript" src="./source/plugin/donkey_activity/static/function.js"></script>';
echo '<script type="text/javascript" src="static/js/calendar.js"></script>';
echo '<script type="text/javascript" src="./static/js/seditor.js"></script>';
?>